import * as THREE from "three";
import Manager from './Manager';
export default class Particles {
    particlesCount = 200;
    positions = null;
    particlesGeometry = null;

    cube = null;
    constructor() {
        this.manager = new Manager()
        this.scene = this.manager.scene;
        this.cube = this.manager.cube;

        this.createPointsPositions();
        this.createParticlesGeometry();
        this.createParticlesMat();
        this.createParticles();
    }

    createPointsPositions() {
        this.positions = new Float32Array(this.particlesCount * 3);

        for (let i = 0; i < this.particlesCount; i++) {
            this.positions[i * 3 + 0] = (Math.random() - 0.5) * 10;
            this.positions[i * 3 + 1] =
                this.cube.objectsDistance * 0.5 -
                Math.random() * this.cube.objectsDistance * this.cube.sectionMeshes.length;
            this.positions[i * 3 + 2] = (Math.random() - 0.5) * 10;
        }
    }

    createParticlesGeometry() {
        this.particlesGeometry = new THREE.BufferGeometry();
        this.particlesGeometry.setAttribute(
            "position",
            new THREE.BufferAttribute(this.positions, 3)
        );
    }
    createParticlesMat() {
        // Material
        this.particlesMaterial = new THREE.PointsMaterial({
            color: this.cube.materialColor,
            sizeAttenuation: new THREE.TextureLoader(),
            size: 0.03,
        });
    }
    createParticles() {
        const particles = new THREE.Points(this.particlesGeometry, this.particlesMaterial);
        this.scene.add(particles);
    }
}